package com.nageoffer.shortlink.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nageoffer.shortlink.project.common.convention.result.Result;
import com.nageoffer.shortlink.project.common.convention.result.Results;
import com.nageoffer.shortlink.project.dto.req.MoveInRecycleBinReqDTO;
import com.nageoffer.shortlink.project.dto.req.RecoverRecycleBinReqDTO;
import com.nageoffer.shortlink.project.dto.req.RemoveRecycleBinReqDTO;
import com.nageoffer.shortlink.project.dto.req.ShortLinkRecycleBinPageReqDTO;
import com.nageoffer.shortlink.project.dto.resp.ShortLinkPageRespDTO;
import com.nageoffer.shortlink.project.service.RecycleBinService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class RecycleBinController {
    private final RecycleBinService recycleBinService;

    /**
     * 移动短链接到回收站
     */
    @PostMapping("/api/short-link/v1/recycle-bin/save")
    public Result<Void> saveShortLinkToRecycleBin(@RequestBody MoveInRecycleBinReqDTO moveInRecycleBinReqDTO) {
        recycleBinService.saveShortLinkToRecycleBin(moveInRecycleBinReqDTO);
        return Results.success();
    }

    /**
     * 回收站分页查询
     */
    @GetMapping("/api/short-link/v1/recycle-bin/page")
    public Result<IPage<ShortLinkPageRespDTO>> pageShortLink(ShortLinkRecycleBinPageReqDTO shortLinkRecycleBinPageReqDTO) {

        return Results.success(recycleBinService.pageShortLink(shortLinkRecycleBinPageReqDTO));
    }

    /**
     * 从回收站恢复短链接
     */
    @PostMapping("/api/short-link/v1/recycle-bin/recover")
    public Result<Void> recoverRecycleBin(@RequestBody RecoverRecycleBinReqDTO recoverRecycleBinReqDTO) {
        recycleBinService.recoverRecycleBin(recoverRecycleBinReqDTO);
        return Results.success();
    }

    /**
     * 从回收站移除短链接
     */
    @PostMapping("/api/short-link/v1/recycle-bin/remove")
    public Result<Void> removeRecycleBin(@RequestBody RemoveRecycleBinReqDTO removeRecycleBinReqDTO) {
        recycleBinService.removeRecycleBin(removeRecycleBinReqDTO);
        return Results.success();
    }
}
